import { buildAssetSource } from '@/utils';
import { isApp } from '@/utils/platform.utils';
import { asyncTimeout } from '@/utils/promise.utils';

export async function loadFont() {
  if (isApp) {
    // app 需要延时加载
    await asyncTimeout(1000);
  }

  uni.loadFontFace({
    global: true,
    family: 'AlibabaPuHuiTiRegular',
    source: `url(${buildAssetSource('Alibaba_PuHuiTi_2.0_55_Regular_55_Regular.ttf')})`,
    success: () => {
    },
    fail: e => {
      console.log('>>>>字体加载失败', e);
    }
  });

  uni.loadFontFace({
    global: true,
    family: 'AlibabaPuHuiTiMedium',
    source: `url(${buildAssetSource('Alibaba_PuHuiTi_2.0_65_Medium_65_Medium.ttf')})`
  });

  uni.loadFontFace({
    global: true,
    family: 'AlibabaPuHuiTiBold',
    source: `url(${buildAssetSource('Alibaba_PuHuiTi_2.0_55_Regular_85_Bold.ttf')})`
  });
}
